package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.Permission;
import com.itheima.pojo.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper extends BaseMapper<User> {
    @Select("select * from t_user where user_name=#{username}")
    User getByUsername(String username);


    @Select("SELECT * FROM t_permission \n" +
            "WHERE id IN(\n" +
            "\tSELECT permission_id FROM t_role_permission \n" +
            "\tWHERE role_id IN( SELECT role_id FROM t_role_user WHERE user_id = #{id})\n" +
            "           )")
    List<Permission> findPermissionsByUserId(Long id);
    @Update("update t_user set pwd =#{pw} where id ")
    boolean updatePW(@Param("pw") String pw);
}
